import random
def shortBubbleSort(alist):
    exchanges = True
    passnum = len(alist)-1 # 交换次数
    print(alist)
    while passnum > 0 and exchanges:
        exchanges = False
        for i in range(passnum):
            if alist[i] > alist[i+1]:
                exchanges = True
                alist[i],alist[i+1]=alist[i+1],alist[i]
        passnum -= 1
    
    print(alist)


def test_shortBubbleSort():
    seq = list(range(10)) 
    random.shuffle(seq)  
    sorted_seq = sorted(seq)  
    shortBubbleSort(seq)
    assert seq == sorted_seq
    
test_shortBubbleSort()